package xyz.chaobei.thread.vol;

/**
 * @copyright (C), 2015-2020
 * @fileName: VolatileObj
 * @author: MRC
 * @date: 2021/2/1 22:57
 * @description:
 */
public class VolatileObj {
    /**
     * 使用volatile 声明内存可见对象
     */
    private volatile boolean isSave = false;
    private int num = 0;

    public void reader() {
        if (isSave) {
            System.out.println("num=" + num);
        }
    }

    public void writer() {
        num = 1;
        isSave = true;
    }

}
